gdkevents: Don't ignore modifiers that are not currently active
authorSimon McVittie <smcv@debian.org>
Sat, 17 Sep 2022 17:53:00 +0000 (18:53 +0100)
committerSimon McVittie <smcv@debian.org>
Sat, 17 Sep 2022 18:40:53 +0000 (19:40 +0100)
commit79285bd63ee9834c2e77ff9639d14a4cd6b7c3c8
tree560cda984d0273eae2e6d4c9aa9fb7e7fa28fc80
parent3a941eff4aa0ad66e0aa34e6528bc4d78c5e5d5e
gdkevents: Don't ignore modifiers that are not currently active

The X11 backend can mark modifiers like Shift as consumed even if they
aren't actually active, which seems to be something to do with making
shortcuts like `<Control><Shift>plus` and `<Control>plus` work as
intended regardless of whether the plus symbol is obtained by pressing
Shift and a key (like `+/=` on American, British or French keyboards)
or not (like `*/+` on German keyboards).

However, this can go badly wrong when the modifier is *not* pressed.
For example, terminals normally have separate bindings for `<Control>c`
(send SIGINT) and `<Control><Shift>c` (copy). If we disregard the
consumed modifiers completely, when the X11 backend marks Shift as
consumed, pressing Ctrl+c would send SIGINT *and* copy to the clipboard,
which is not what was intended.

By masking out the members of `consumed` that are not in `state`, we
get the same interpretation for X11 and Wayland, and ensure that
keyboard shortcuts that explicitly mention Shift can only be triggered
while holding Shift. It continues to be possible to trigger keyboard
shortcuts that do not explicitly mention Shift (such as `<Control>plus`)
while holding Shift, if the backend reports Shift as having been
consumed in order to generate the plus keysym.

Resolves: https://gitlab.gnome.org/GNOME/gtk/-/issues/5095
Bug-Debian: https://bugs.debian.org/1016927
Signed-off-by: Simon McVittie <smcv@debian.org>
gdk/gdkevents.c